﻿using System.Collections.Generic;
using System.Linq;
using Week6Music_API_and_Angular_.Adapter.Interfaces;
using Week6Music_API_and_Angular_.Data;
using Week6Music_API_and_Angular_.Models;

namespace Week6Music_API_and_Angular_.Adapter.Adapter
{
    public class ArtistAdapter : IArtistAdapter
    {
        public List<ArtistVM> GetAllArtists()
        {
            List<ArtistVM> model;
            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                model = db.Artist.Select(x => new ArtistVM()
                {
                    ArtistId = x.Id,
                    Genre = x.Genre,
                    ImgUrl = x.ImgUrl,
                    Name = x.Name,
                    OnTour = x.OnTour
                }).ToList();
            }
            return model;
        }

        public ArtistDetailsVM GetArtistDetails(int id)
        {
            ArtistDetailsVM artist;
            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                artist = db.Artist.Where(a => a.Id == id).Select(x => new ArtistDetailsVM()
                    {
                        Genre = x.Genre,
                        Id = x.Id,
                        ImgUrl = x.ImgUrl,
                        Name = x.Name,
                        OnTour = x.OnTour,

                        FeaturedEvents = x.FeaturedEvents.Select(e => new EventVM()
                        {
                            EventPoster = e.EventPoster,
                            EventName = e.EventName,
                            Date = e.Date,
                            price = e.price,
                            ZipCode = e.ZipCode
                        }).ToList(),

                        OpeningEvents = x.OpeningEvents.Select(t => new EventVM()
                        {
                            EventPoster = t.EventPoster,
                            EventName = t.EventName,
                            Date = t.Date,
                            price = t.price,
                            ZipCode = t.ZipCode
                        }).ToList()
                    }).FirstOrDefault();
            }
            return artist;
        }
    }
}